<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/%E6%AD%A6%E6%B1%8932x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/%E6%AD%A6%E6%B1%8916x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib1/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="/lib1/pace/pace-theme-center-simple.min.css">
  <script src="/lib1/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"example.com","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="前言这个需求好像是之前项目上跟短信验证码一起写的代码，这里突然想起来，准备将这个需求的实现总结分析一下，在后续再遇到类似需求时，有一个合适的参考对象。这个需求主要在于拼图验证码在前端这里会比较复杂并且深入。相比文字拼写，12306的图片验证码都没有拼图验证码对前端的要求来的复杂。 一、弹窗和弹窗组件抱歉，这里我偷懒了直接用了elementUI的el-popover组件，所以小伙伴不懂的直接看ele">
<meta property="og:type" content="article">
<meta property="og:title" content="滑动图片验证码">
<meta property="og:url" content="http://example.com/2021/09/10/%E5%AD%A6%E6%A0%A1%E9%A1%B9%E7%9B%AE%E5%BA%94%E7%94%A8/%E6%BB%91%E5%8A%A8%E5%9B%BE%E7%89%87%E9%AA%8C%E8%AF%81%E7%A0%81/index.html">
<meta property="og:site_name" content="Technological Blog">
<meta property="og:description" content="前言这个需求好像是之前项目上跟短信验证码一起写的代码，这里突然想起来，准备将这个需求的实现总结分析一下，在后续再遇到类似需求时，有一个合适的参考对象。这个需求主要在于拼图验证码在前端这里会比较复杂并且深入。相比文字拼写，12306的图片验证码都没有拼图验证码对前端的要求来的复杂。 一、弹窗和弹窗组件抱歉，这里我偷懒了直接用了elementUI的el-popover组件，所以小伙伴不懂的直接看ele">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://example.com/image/%E6%BB%91%E5%8A%A8%E5%9B%BE%E7%89%87%E9%AA%8C%E8%AF%81%E7%A0%81/8349f66d075642e2836e1fc9dfc10991tplv-k3u1fbpfcp-watermark.awebp">
<meta property="og:image" content="http://example.com/image/%E6%BB%91%E5%8A%A8%E5%9B%BE%E7%89%87%E9%AA%8C%E8%AF%81%E7%A0%81/af4c4e3b4c6e429d8f1bbfa33b410badtplv-k3u1fbpfcp-watermark.awebp">
<meta property="article:published_time" content="2021-09-10T13:28:16.000Z">
<meta property="article:modified_time" content="2021-11-03T08:31:35.761Z">
<meta property="article:author" content="Li Yudong">
<meta property="article:tag" content="学校项目应用">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://example.com/image/%E6%BB%91%E5%8A%A8%E5%9B%BE%E7%89%87%E9%AA%8C%E8%AF%81%E7%A0%81/8349f66d075642e2836e1fc9dfc10991tplv-k3u1fbpfcp-watermark.awebp">

<link rel="canonical" href="http://example.com/2021/09/10/%E5%AD%A6%E6%A0%A1%E9%A1%B9%E7%9B%AE%E5%BA%94%E7%94%A8/%E6%BB%91%E5%8A%A8%E5%9B%BE%E7%89%87%E9%AA%8C%E8%AF%81%E7%A0%81/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>滑动图片验证码 | Technological Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Technological Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">IT小白的成长之旅</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="tags fa-fw"></i>标签<span class="badge">18</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="th fa-fw"></i>分类<span class="badge">14</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="archive fa-fw"></i>归档<span class="badge">95</span></a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

  <a href="https://github.com/tiarmor1" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://example.com/2021/09/10/%E5%AD%A6%E6%A0%A1%E9%A1%B9%E7%9B%AE%E5%BA%94%E7%94%A8/%E6%BB%91%E5%8A%A8%E5%9B%BE%E7%89%87%E9%AA%8C%E8%AF%81%E7%A0%81/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/author.jpg">
      <meta itemprop="name" content="Li Yudong">
      <meta itemprop="description" content="">
    </span>
    
    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Technological Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          滑动图片验证码
        </h1>
    
        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
    
              <time title="创建时间：2021-09-10 21:28:16" itemprop="dateCreated datePublished" datetime="2021-09-10T21:28:16+08:00">2021-09-10</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2021-11-03 16:31:35" itemprop="dateModified" datetime="2021-11-03T16:31:35+08:00">2021-11-03</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E5%AD%A6%E6%A0%A1%E9%A1%B9%E7%9B%AE%E5%BA%94%E7%94%A8/" itemprop="url" rel="index"><span itemprop="name">学校项目应用</span></a>
                </span>
            </span>
    
          
    
        </div>
      </header>
    
    
    
    
    <div class="post-body" itemprop="articleBody">
    
      
        <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>这个需求好像是之前项目上跟短信验证码一起写的代码，这里突然想起来，准备将这个需求的实现总结分析一下，在后续再遇到类似需求时，有一个合适的参考对象。这个需求主要在于拼图验证码在前端这里会比较复杂并且深入。相比文字拼写，12306的图片验证码都没有拼图验证码对前端的要求来的复杂。</p>
<h2 id="一、弹窗和弹窗组件"><a href="#一、弹窗和弹窗组件" class="headerlink" title="一、弹窗和弹窗组件"></a>一、弹窗和弹窗组件</h2><p>抱歉，这里我偷懒了直接用了elementUI的el-popover组件，所以小伙伴不懂的直接看elementUI官网的说明。</p>
<h2 id="二、编写基础结构"><a href="#二、编写基础结构" class="headerlink" title="二、编写基础结构"></a>二、编写基础结构</h2><p>这块属于html的基础内容，也就标题党了</p>
<h2 id="三、canvas绘制图片"><a href="#三、canvas绘制图片" class="headerlink" title="三、canvas绘制图片"></a>三、canvas绘制图片</h2><h3 id="1、canvas绘制外部img图片"><a href="#1、canvas绘制外部img图片" class="headerlink" title="1、canvas绘制外部img图片"></a>1、canvas绘制外部img图片</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> mainDom = <span class="built_in">document</span>.querySelector(<span class="string">"#codeImg"</span>);</span><br><span class="line"><span class="keyword">let</span> bg = mainDom.getContext(<span class="string">"2d"</span>);</span><br><span class="line"><span class="keyword">let</span> width = mainDom.width;</span><br><span class="line"><span class="keyword">let</span> height = mainDom.height;</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> blockDom = <span class="built_in">document</span>.querySelector(<span class="string">"#sliderBlock"</span>);</span><br><span class="line"><span class="keyword">let</span> block = blockDom.getContext(<span class="string">"2d"</span>);</span><br><span class="line"><span class="comment">//重新赋值，让canvas进行重新绘制</span></span><br><span class="line">blockDom.height = height;</span><br><span class="line">mainDom.height = height;</span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> imgsrc = <span class="built_in">require</span>(<span class="string">"../assets/images/back.jpg"</span>);</span><br><span class="line"><span class="keyword">let</span> img = <span class="built_in">document</span>.createElement(<span class="string">"img"</span>);</span><br><span class="line">img.style.objectFit = <span class="string">"scale-down"</span>;</span><br><span class="line">img.src = imgsrc;</span><br><span class="line">img.onload = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  bg.drawImage(img, <span class="number">0</span>, <span class="number">0</span>, width, height);</span><br><span class="line">  block.drawImage(img, <span class="number">0</span>, <span class="number">0</span>, width, height);</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<p>这里我绘制了两个canvas，因为一个是背景一个是滑块</p>
<p>核心在于</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> mainDom = <span class="built_in">document</span>.querySelector(<span class="string">"#codeImg"</span>);</span><br><span class="line"><span class="keyword">let</span> imgsrc = <span class="built_in">require</span>(<span class="string">"../assets/images/back.jpg"</span>);</span><br><span class="line"><span class="keyword">let</span> bg = mainDom.getContext(<span class="string">"2d"</span>);</span><br><span class="line"><span class="keyword">let</span> img = <span class="built_in">document</span>.createElement(<span class="string">"img"</span>);</span><br><span class="line">img.onload = <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    bg.drawImage(img, <span class="number">0</span>, <span class="number">0</span>, width, height);</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h3 id="2、canvas绘制滑块部分"><a href="#2、canvas绘制滑块部分" class="headerlink" title="2、canvas绘制滑块部分"></a>2、canvas绘制滑块部分</h3><p><img src="/../../image/%E6%BB%91%E5%8A%A8%E5%9B%BE%E7%89%87%E9%AA%8C%E8%AF%81%E7%A0%81/8349f66d075642e2836e1fc9dfc10991tplv-k3u1fbpfcp-watermark.awebp" alt="img"></p>
<p>代码部分：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br></pre></td><td class="code"><pre><span class="line">drawBlock(ctx, xy = &#123; <span class="attr">x</span>: <span class="number">254</span>, <span class="attr">y</span>: <span class="number">109</span>, <span class="attr">r</span>: <span class="number">9</span> &#125;, type) &#123;</span><br><span class="line">  <span class="keyword">let</span> x = xy.x,</span><br><span class="line">    y = xy.y,</span><br><span class="line">    r = xy.r,</span><br><span class="line">    w = <span class="number">40</span>;</span><br><span class="line">  <span class="keyword">let</span> PI = <span class="built_in">Math</span>.PI;</span><br><span class="line">  <span class="comment">//绘制</span></span><br><span class="line">  ctx.beginPath();</span><br><span class="line">  <span class="comment">//left</span></span><br><span class="line">  ctx.moveTo(x, y);</span><br><span class="line">  <span class="comment">//top</span></span><br><span class="line">  ctx.arc(x + (w + <span class="number">5</span>) / <span class="number">2</span>, y, r, -PI, <span class="number">0</span>, <span class="literal">true</span>);</span><br><span class="line">  ctx.lineTo(x + w + <span class="number">5</span>, y);</span><br><span class="line">  <span class="comment">//right</span></span><br><span class="line">  ctx.arc(x + w + <span class="number">5</span>, y + w / <span class="number">2</span>, r, <span class="number">1.5</span> * PI, <span class="number">0.5</span> * PI, <span class="literal">false</span>);</span><br><span class="line">  ctx.lineTo(x + w + <span class="number">5</span>, y + w);</span><br><span class="line">  <span class="comment">//bottom</span></span><br><span class="line">  ctx.arc(x + (w + <span class="number">5</span>) / <span class="number">2</span>, y + w, r, <span class="number">0</span>, PI, <span class="literal">false</span>);</span><br><span class="line">  ctx.lineTo(x, y + w);</span><br><span class="line">  ctx.arc(x, y + w / <span class="number">2</span>, r, <span class="number">0.5</span> * PI, <span class="number">1.5</span> * PI, <span class="literal">true</span>);</span><br><span class="line">  ctx.lineTo(x, y);</span><br><span class="line">  <span class="comment">//修饰，没有会看不出效果</span></span><br><span class="line">  ctx.lineWidth = <span class="number">1</span>;</span><br><span class="line">  ctx.fillStyle = <span class="string">"rgba(255, 255, 255, 0.5)"</span>;</span><br><span class="line">  ctx.strokeStyle = <span class="string">"rgba(255, 255, 255, 0.5)"</span>;</span><br><span class="line">  ctx.stroke();</span><br><span class="line">  ctx[type]();</span><br><span class="line">  ctx.globalCompositeOperation = <span class="string">"xor"</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>解释下：</p>
<p>参数是传入canvas对象</p>
<p>x，y轴数据</p>
<p>剪切还是填充的canvas函数（fill，clip）</p>
<p>绘制难点：（很重要，不然你没法理解它怎么绘制的）</p>
<p>绘制主要是需要理解这里的绘制是根据你设置一个起始点坐标，然后你绘制第二次的时候线就会连接到第二个点，依次连接最后回到原点就形成一个完整的图形。</p>
<p><img src="/../../image/%E6%BB%91%E5%8A%A8%E5%9B%BE%E7%89%87%E9%AA%8C%E8%AF%81%E7%A0%81/af4c4e3b4c6e429d8f1bbfa33b410badtplv-k3u1fbpfcp-watermark.awebp" alt="img"></p>
<p>用的是arc参数，主要是看这个图</p>
<p>fill是用于填充绘制的部分，clip是裁剪出绘制的部分，利用这个就可以出现一个扣掉的图片和一个裁剪出来的图片。</p>
<p>完成之后就是我的那个函数了。大家可以直接拿去用。</p>
<h3 id="3、让元素跟随鼠标点击之后滑动"><a href="#3、让元素跟随鼠标点击之后滑动" class="headerlink" title="3、让元素跟随鼠标点击之后滑动"></a>3、让元素跟随鼠标点击之后滑动</h3><p>这里其实原理非常简单，就是有一个注意点。</p>
<p>原理：</p>
<p>鼠标点击之后记录当前坐标，然后随着（mousemove）滚动的时候修改元素的left和top值就行了。</p>
<p>还有一点就是鼠标快速滑动会导致丢失滑动效果，这里需要用document，不能是元素级别的监听。</p>
<p>元素上面我只需要鉴定按下mousedown</p>
<p>代码：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//鼠标按下</span></span><br><span class="line">drag(e) &#123;</span><br><span class="line">  <span class="built_in">console</span>.log(<span class="string">"鼠标按下"</span>, e);</span><br><span class="line">  <span class="keyword">let</span> dom = e.target; <span class="comment">//dom元素</span></span><br><span class="line">  <span class="keyword">let</span> slider = <span class="built_in">document</span>.querySelector(<span class="string">"#sliderBlock"</span>); <span class="comment">//滑块dom</span></span><br><span class="line">  <span class="keyword">const</span> downCoordinate = &#123; <span class="attr">x</span>: e.x, <span class="attr">y</span>: e.y &#125;;</span><br><span class="line"></span><br><span class="line">  <span class="comment">//正确的滑块数据</span></span><br><span class="line">  <span class="keyword">let</span> checkx = <span class="built_in">Number</span>(<span class="keyword">this</span>.slider.mx) - <span class="built_in">Number</span>(<span class="keyword">this</span>.slider.bx);</span><br><span class="line">  <span class="comment">//x轴数据</span></span><br><span class="line">  <span class="keyword">let</span> x = <span class="number">0</span>;</span><br><span class="line">  <span class="keyword">const</span> move = <span class="function"><span class="params">moveEV</span> =&gt;</span> &#123;</span><br><span class="line">    x = moveEV.x - downCoordinate.x;</span><br><span class="line">    <span class="comment">//y = moveEV.y - downCoordinate.y;</span></span><br><span class="line">    <span class="keyword">if</span> (x &gt;= <span class="number">251</span> || x &lt;= <span class="number">0</span>) <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">    dom.style.left = x + <span class="string">"px"</span>;</span><br><span class="line">    <span class="comment">//dom.style.top = y + "px";</span></span><br><span class="line">    slider.style.left = x + <span class="string">"px"</span>;</span><br><span class="line">  &#125;;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">const</span> up = <span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="built_in">document</span>.removeEventListener(<span class="string">"mousemove"</span>, move);</span><br><span class="line">    <span class="built_in">document</span>.removeEventListener(<span class="string">"mouseup"</span>, up);</span><br><span class="line">    dom.style.left = <span class="string">""</span>;</span><br><span class="line"></span><br><span class="line">    <span class="built_in">console</span>.log(x, checkx);</span><br><span class="line">    <span class="keyword">let</span> max = checkx - <span class="number">5</span>;</span><br><span class="line">    <span class="keyword">let</span> min = checkx - <span class="number">10</span>;</span><br><span class="line">    <span class="comment">//允许正负误差1</span></span><br><span class="line">    <span class="keyword">if</span> ((max &gt;= x &amp;&amp; x &gt;= min) || x === checkx) &#123;</span><br><span class="line">      <span class="built_in">console</span>.log(<span class="string">"滑动解锁成功"</span>);</span><br><span class="line">      <span class="keyword">this</span>.puzzle = <span class="literal">true</span>;</span><br><span class="line">      <span class="keyword">this</span>.tips = <span class="string">"验证成功"</span>;</span><br><span class="line">      setTimeout(<span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="keyword">this</span>.visible = <span class="literal">false</span>;</span><br><span class="line">      &#125;, <span class="number">500</span>);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      <span class="built_in">console</span>.log(<span class="string">"拼图位置不正确"</span>);</span><br><span class="line">      <span class="keyword">this</span>.tips = <span class="string">"验证失败，请重试"</span>;</span><br><span class="line">      <span class="keyword">this</span>.puzzle = <span class="literal">false</span>;</span><br><span class="line">      <span class="keyword">this</span>.canvasInit();</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;;</span><br><span class="line"></span><br><span class="line">  <span class="built_in">document</span>.addEventListener(<span class="string">"mousemove"</span>, move);</span><br><span class="line">  <span class="built_in">document</span>.addEventListener(<span class="string">"mouseup"</span>, up);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="四、完整的页面代码"><a href="#四、完整的页面代码" class="headerlink" title="四、完整的页面代码"></a>四、完整的页面代码</h2><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">template</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">"login"</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">el-form</span> <span class="attr">class</span>=<span class="string">"loginFrom"</span> <span class="attr">:model</span>=<span class="string">"logindata"</span> <span class="attr">:rules</span>=<span class="string">"rules"</span> <span class="attr">ref</span>=<span class="string">"ruleForm"</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">el-form-item</span> <span class="attr">class</span>=<span class="string">"login-item"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">h1</span> <span class="attr">class</span>=<span class="string">"login-title"</span>&gt;</span>海天酱油登录中心<span class="tag">&lt;/<span class="name">h1</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">el-form-item</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">el-form-item</span> <span class="attr">prop</span>=<span class="string">"userName"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">el-input</span></span></span><br><span class="line"><span class="tag">          <span class="attr">class</span>=<span class="string">"login-inputorbuttom"</span></span></span><br><span class="line"><span class="tag">          <span class="attr">prefix-icon</span>=<span class="string">"el-icon-user"</span></span></span><br><span class="line"><span class="tag">          <span class="attr">placeholder</span>=<span class="string">"登录名"</span></span></span><br><span class="line"><span class="tag">          <span class="attr">v-model</span>=<span class="string">"logindata.userName"</span></span></span><br><span class="line"><span class="tag">        &gt;</span><span class="tag">&lt;/<span class="name">el-input</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">el-form-item</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">el-form-item</span> <span class="attr">prop</span>=<span class="string">"password"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">el-input</span></span></span><br><span class="line"><span class="tag">          <span class="attr">class</span>=<span class="string">"login-inputorbuttom"</span></span></span><br><span class="line"><span class="tag">          <span class="attr">prefix-icon</span>=<span class="string">"el-icon-lock"</span></span></span><br><span class="line"><span class="tag">          <span class="attr">placeholder</span>=<span class="string">"密码"</span></span></span><br><span class="line"><span class="tag">          <span class="attr">v-model</span>=<span class="string">"logindata.password"</span></span></span><br><span class="line"><span class="tag">        &gt;</span><span class="tag">&lt;/<span class="name">el-input</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">el-form-item</span>&gt;</span></span><br><span class="line">      <span class="comment">&lt;!--&lt;el-form-item prop="verificationCode"&gt;</span></span><br><span class="line"><span class="comment">        &lt;el-input</span></span><br><span class="line"><span class="comment">          class="login-inputorbuttom"</span></span><br><span class="line"><span class="comment">          v-model="logindata.verificationCode"</span></span><br><span class="line"><span class="comment">        &gt;&lt;/el-input&gt;</span></span><br><span class="line"><span class="comment">      &lt;/el-form-item&gt;--&gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">el-form-item</span> <span class="attr">class</span>=<span class="string">"login-item"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">el-button</span></span></span><br><span class="line"><span class="tag">          <span class="attr">class</span>=<span class="string">"login-inputorbuttom login-bottom"</span></span></span><br><span class="line"><span class="tag">          <span class="attr">type</span>=<span class="string">"primary"</span></span></span><br><span class="line"><span class="tag">          <span class="attr">v-popover:popover</span></span></span><br><span class="line"><span class="tag">          @<span class="attr">click</span>=<span class="string">"visible = !visible"</span></span></span><br><span class="line"><span class="tag">          &gt;</span>登 录<span class="tag">&lt;/<span class="name">el-button</span></span></span><br><span class="line"><span class="tag">        &gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">el-form-item</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">el-form</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--验证码弹窗--&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">el-popover</span></span></span><br><span class="line"><span class="tag">      <span class="attr">popper-class</span>=<span class="string">"slidingPictures"</span></span></span><br><span class="line"><span class="tag">      <span class="attr">ref</span>=<span class="string">"popover"</span></span></span><br><span class="line"><span class="tag">      <span class="attr">trigger</span>=<span class="string">"manual"</span></span></span><br><span class="line"><span class="tag">      <span class="attr">v-model</span>=<span class="string">"visible"</span></span></span><br><span class="line"><span class="tag">    &gt;</span></span><br><span class="line">      <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"sliding-pictures"</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"vimg"</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">canvas</span> <span class="attr">id</span>=<span class="string">"sliderBlock"</span>&gt;</span><span class="tag">&lt;/<span class="name">canvas</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">canvas</span> <span class="attr">id</span>=<span class="string">"codeImg"</span>&gt;</span><span class="tag">&lt;/<span class="name">canvas</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"slider"</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"track"</span> <span class="attr">:class</span>=<span class="string">"&#123; pintuTrue: puzzle &#125;"</span>&gt;</span></span><br><span class="line">            &#123;&#123; tips &#125;&#125;</span><br><span class="line">          <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"button el-icon-s-grid"</span> @<span class="attr">mousedown.prevent</span>=<span class="string">"drag"</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">div</span> <span class="attr">class</span>=<span class="string">"operation"</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">span</span></span></span><br><span class="line"><span class="tag">            <span class="attr">title</span>=<span class="string">"关闭验证码"</span></span></span><br><span class="line"><span class="tag">            @<span class="attr">click</span>=<span class="string">"visible = false"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">class</span>=<span class="string">"el-icon-circle-close"</span></span></span><br><span class="line"><span class="tag">          &gt;</span><span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">          <span class="tag">&lt;<span class="name">span</span></span></span><br><span class="line"><span class="tag">            <span class="attr">title</span>=<span class="string">"刷新验证码"</span></span></span><br><span class="line"><span class="tag">            @<span class="attr">click</span>=<span class="string">"canvasInit"</span></span></span><br><span class="line"><span class="tag">            <span class="attr">class</span>=<span class="string">"el-icon-refresh-left"</span></span></span><br><span class="line"><span class="tag">          &gt;</span><span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">      <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">el-popover</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">template</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="javascript"><span class="keyword">export</span> <span class="keyword">default</span> &#123;</span></span><br><span class="line"><span class="actionscript">  name: <span class="string">"login"</span>,</span></span><br><span class="line">  data() &#123;</span><br><span class="line"><span class="actionscript">    <span class="keyword">return</span> &#123;</span></span><br><span class="line"><span class="actionscript">      tips: <span class="string">"拖动左边滑块完成上方拼图"</span>,</span></span><br><span class="line">      logindata: &#123;</span><br><span class="line"><span class="actionscript">        userName: <span class="string">""</span>,</span></span><br><span class="line"><span class="actionscript">        password: <span class="string">""</span>,</span></span><br><span class="line"><span class="actionscript">        verificationCode: <span class="string">""</span></span></span><br><span class="line">      &#125;,</span><br><span class="line">      rules: &#123;&#125;,</span><br><span class="line"><span class="actionscript">      visible: <span class="literal">false</span>,</span></span><br><span class="line"><span class="actionscript">      <span class="comment">//滑块x轴数据</span></span></span><br><span class="line">      slider: &#123;</span><br><span class="line">        mx: 0,</span><br><span class="line">        bx: 0</span><br><span class="line">      &#125;,</span><br><span class="line"><span class="actionscript">      <span class="comment">//拼图是否正确</span></span></span><br><span class="line"><span class="actionscript">      puzzle: <span class="literal">false</span></span></span><br><span class="line">    &#125;;</span><br><span class="line">  &#125;,</span><br><span class="line">  watch: &#123;</span><br><span class="line">    visible(e) &#123;</span><br><span class="line"><span class="actionscript">      <span class="keyword">if</span> (e === <span class="literal">true</span>) &#123;</span></span><br><span class="line"><span class="actionscript">        <span class="keyword">this</span>.canvasInit();</span></span><br><span class="line"><span class="actionscript">        <span class="keyword">this</span>.puzzle = <span class="literal">false</span>;</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;,</span><br><span class="line">  beforeCreate() &#123;&#125;,</span><br><span class="line">  created() &#123;&#125;,</span><br><span class="line">  beforeMount() &#123;&#125;,</span><br><span class="line">  mounted() &#123;&#125;,</span><br><span class="line">  methods: &#123;</span><br><span class="line"><span class="actionscript">    <span class="comment">//拼图验证码初始化</span></span></span><br><span class="line">    canvasInit() &#123;</span><br><span class="line"><span class="actionscript">      <span class="comment">//生成指定区间的随机数</span></span></span><br><span class="line"><span class="javascript">      <span class="keyword">const</span> random = <span class="function">(<span class="params">min, max</span>) =&gt;</span> &#123;</span></span><br><span class="line"><span class="javascript">        <span class="keyword">return</span> <span class="built_in">Math</span>.floor(<span class="built_in">Math</span>.random() * (max - min + <span class="number">1</span>) + min);</span></span><br><span class="line">      &#125;;</span><br><span class="line"><span class="actionscript">      <span class="comment">//x: 254, y: 109</span></span></span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> mx = random(<span class="number">127</span>, <span class="number">244</span>),</span></span><br><span class="line">        bx = random(10, 128),</span><br><span class="line">        y = random(10, 99);</span><br><span class="line"></span><br><span class="line"><span class="actionscript">      <span class="keyword">this</span>.slider = &#123; mx, bx &#125;;</span></span><br><span class="line"></span><br><span class="line"><span class="actionscript">      <span class="keyword">this</span>.draw(mx, bx, y);</span></span><br><span class="line">    &#125;,</span><br><span class="line"><span class="actionscript">    <span class="comment">//鼠标按下</span></span></span><br><span class="line">    drag(e) &#123;</span><br><span class="line"><span class="javascript">      <span class="built_in">console</span>.log(<span class="string">"鼠标按下"</span>, e);</span></span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> dom = e.target; <span class="comment">//dom元素</span></span></span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> slider = <span class="built_in">document</span>.querySelector(<span class="string">"#sliderBlock"</span>); <span class="comment">//滑块dom</span></span></span><br><span class="line"><span class="actionscript">      <span class="keyword">const</span> downCoordinate = &#123; x: e.x, y: e.y &#125;;</span></span><br><span class="line"></span><br><span class="line"><span class="actionscript">      <span class="comment">//正确的滑块数据</span></span></span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> checkx = <span class="built_in">Number</span>(<span class="keyword">this</span>.slider.mx) - <span class="built_in">Number</span>(<span class="keyword">this</span>.slider.bx);</span></span><br><span class="line"><span class="actionscript">      <span class="comment">//x轴数据</span></span></span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> x = <span class="number">0</span>;</span></span><br><span class="line"><span class="javascript">      <span class="keyword">const</span> move = <span class="function"><span class="params">moveEV</span> =&gt;</span> &#123;</span></span><br><span class="line">        x = moveEV.x - downCoordinate.x;</span><br><span class="line"><span class="actionscript">        <span class="comment">//y = moveEV.y - downCoordinate.y;</span></span></span><br><span class="line"><span class="actionscript">        <span class="keyword">if</span> (x &gt;= <span class="number">251</span> || x &lt;= <span class="number">0</span>) <span class="keyword">return</span> <span class="literal">false</span>;</span></span><br><span class="line"><span class="actionscript">        dom.style.left = x + <span class="string">"px"</span>;</span></span><br><span class="line"><span class="actionscript">        <span class="comment">//dom.style.top = y + "px";</span></span></span><br><span class="line"><span class="actionscript">        slider.style.left = x + <span class="string">"px"</span>;</span></span><br><span class="line">      &#125;;</span><br><span class="line"></span><br><span class="line"><span class="javascript">      <span class="keyword">const</span> up = <span class="function"><span class="params">()</span> =&gt;</span> &#123;</span></span><br><span class="line"><span class="javascript">        <span class="built_in">document</span>.removeEventListener(<span class="string">"mousemove"</span>, move);</span></span><br><span class="line"><span class="javascript">        <span class="built_in">document</span>.removeEventListener(<span class="string">"mouseup"</span>, up);</span></span><br><span class="line"><span class="actionscript">        dom.style.left = <span class="string">""</span>;</span></span><br><span class="line"></span><br><span class="line"><span class="javascript">        <span class="built_in">console</span>.log(x, checkx);</span></span><br><span class="line"><span class="javascript">        <span class="keyword">let</span> max = checkx - <span class="number">5</span>;</span></span><br><span class="line"><span class="javascript">        <span class="keyword">let</span> min = checkx - <span class="number">10</span>;</span></span><br><span class="line"><span class="actionscript">        <span class="comment">//允许正负误差1</span></span></span><br><span class="line">        if ((max &gt;= x &amp;&amp; x &gt;= min) || x === checkx) &#123;</span><br><span class="line"><span class="javascript">          <span class="built_in">console</span>.log(<span class="string">"滑动解锁成功"</span>);</span></span><br><span class="line"><span class="actionscript">          <span class="keyword">this</span>.puzzle = <span class="literal">true</span>;</span></span><br><span class="line"><span class="actionscript">          <span class="keyword">this</span>.tips = <span class="string">"验证成功"</span>;</span></span><br><span class="line"><span class="javascript">          setTimeout(<span class="function"><span class="params">()</span> =&gt;</span> &#123;</span></span><br><span class="line"><span class="actionscript">            <span class="keyword">this</span>.visible = <span class="literal">false</span>;</span></span><br><span class="line">          &#125;, 500);</span><br><span class="line"><span class="actionscript">        &#125; <span class="keyword">else</span> &#123;</span></span><br><span class="line"><span class="javascript">          <span class="built_in">console</span>.log(<span class="string">"拼图位置不正确"</span>);</span></span><br><span class="line"><span class="actionscript">          <span class="keyword">this</span>.tips = <span class="string">"验证失败，请重试"</span>;</span></span><br><span class="line"><span class="actionscript">          <span class="keyword">this</span>.puzzle = <span class="literal">false</span>;</span></span><br><span class="line"><span class="actionscript">          <span class="keyword">this</span>.canvasInit();</span></span><br><span class="line">        &#125;</span><br><span class="line">      &#125;;</span><br><span class="line"></span><br><span class="line"><span class="javascript">      <span class="built_in">document</span>.addEventListener(<span class="string">"mousemove"</span>, move);</span></span><br><span class="line"><span class="javascript">      <span class="built_in">document</span>.addEventListener(<span class="string">"mouseup"</span>, up);</span></span><br><span class="line">    &#125;,</span><br><span class="line">    draw(mx = 200, bx = 20, y = 50) &#123;</span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> mainDom = <span class="built_in">document</span>.querySelector(<span class="string">"#codeImg"</span>);</span></span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> bg = mainDom.getContext(<span class="string">"2d"</span>);</span></span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> width = mainDom.width;</span></span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> height = mainDom.height;</span></span><br><span class="line"></span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> blockDom = <span class="built_in">document</span>.querySelector(<span class="string">"#sliderBlock"</span>);</span></span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> block = blockDom.getContext(<span class="string">"2d"</span>);</span></span><br><span class="line"><span class="actionscript">      <span class="comment">//重新赋值，让canvas进行重新绘制</span></span></span><br><span class="line">      blockDom.height = height;</span><br><span class="line">      mainDom.height = height;</span><br><span class="line"></span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> imgsrc = <span class="built_in">require</span>(<span class="string">"../assets/images/back.jpg"</span>);</span></span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> img = <span class="built_in">document</span>.createElement(<span class="string">"img"</span>);</span></span><br><span class="line"><span class="actionscript">      img.style.objectFit = <span class="string">"scale-down"</span>;</span></span><br><span class="line">      img.src = imgsrc;</span><br><span class="line"><span class="actionscript">      img.onload = <span class="function"><span class="keyword">function</span><span class="params">()</span> </span>&#123;</span></span><br><span class="line">        bg.drawImage(img, 0, 0, width, height);</span><br><span class="line">        block.drawImage(img, 0, 0, width, height);</span><br><span class="line">      &#125;;</span><br><span class="line"></span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> mainxy = &#123; <span class="attr">x</span>: mx, <span class="attr">y</span>: y, <span class="attr">r</span>: <span class="number">9</span> &#125;;</span></span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> blockxy = &#123; <span class="attr">x</span>: bx, <span class="attr">y</span>: y, <span class="attr">r</span>: <span class="number">9</span> &#125;;</span></span><br><span class="line"><span class="actionscript">      <span class="keyword">this</span>.drawBlock(bg, mainxy, <span class="string">"fill"</span>);</span></span><br><span class="line"><span class="actionscript">      <span class="keyword">this</span>.drawBlock(block, blockxy, <span class="string">"clip"</span>);</span></span><br><span class="line">    &#125;,</span><br><span class="line"><span class="actionscript">    <span class="comment">//绘制拼图</span></span></span><br><span class="line">    drawBlock(ctx, xy = &#123; x: 254, y: 109, r: 9 &#125;, type) &#123;</span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> x = xy.x,</span></span><br><span class="line">        y = xy.y,</span><br><span class="line">        r = xy.r,</span><br><span class="line">        w = 40;</span><br><span class="line"><span class="javascript">      <span class="keyword">let</span> PI = <span class="built_in">Math</span>.PI;</span></span><br><span class="line"><span class="actionscript">      <span class="comment">//绘制</span></span></span><br><span class="line">      ctx.beginPath();</span><br><span class="line"><span class="actionscript">      <span class="comment">//left</span></span></span><br><span class="line">      ctx.moveTo(x, y);</span><br><span class="line"><span class="actionscript">      <span class="comment">//top</span></span></span><br><span class="line"><span class="actionscript">      ctx.arc(x + (w + <span class="number">5</span>) / <span class="number">2</span>, y, r, -PI, <span class="number">0</span>, <span class="literal">true</span>);</span></span><br><span class="line">      ctx.lineTo(x + w + 5, y);</span><br><span class="line"><span class="actionscript">      <span class="comment">//right</span></span></span><br><span class="line"><span class="actionscript">      ctx.arc(x + w + <span class="number">5</span>, y + w / <span class="number">2</span>, r, <span class="number">1.5</span> * PI, <span class="number">0.5</span> * PI, <span class="literal">false</span>);</span></span><br><span class="line">      ctx.lineTo(x + w + 5, y + w);</span><br><span class="line"><span class="actionscript">      <span class="comment">//bottom</span></span></span><br><span class="line"><span class="actionscript">      ctx.arc(x + (w + <span class="number">5</span>) / <span class="number">2</span>, y + w, r, <span class="number">0</span>, PI, <span class="literal">false</span>);</span></span><br><span class="line">      ctx.lineTo(x, y + w);</span><br><span class="line"><span class="actionscript">      ctx.arc(x, y + w / <span class="number">2</span>, r, <span class="number">0.5</span> * PI, <span class="number">1.5</span> * PI, <span class="literal">true</span>);</span></span><br><span class="line">      ctx.lineTo(x, y);</span><br><span class="line"><span class="actionscript">      <span class="comment">//修饰，没有会看不出效果</span></span></span><br><span class="line">      ctx.lineWidth = 1;</span><br><span class="line"><span class="actionscript">      ctx.fillStyle = <span class="string">"rgba(255, 255, 255, 0.5)"</span>;</span></span><br><span class="line"><span class="actionscript">      ctx.strokeStyle = <span class="string">"rgba(255, 255, 255, 0.5)"</span>;</span></span><br><span class="line">      ctx.stroke();</span><br><span class="line">      ctx[type]();</span><br><span class="line"><span class="actionscript">      ctx.globalCompositeOperation = <span class="string">"xor"</span>;</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;;</span><br><span class="line"><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="css"><span class="selector-class">.slidingPictures</span> &#123;</span></span><br><span class="line">  padding: 0;</span><br><span class="line">  width: 300px;</span><br><span class="line">  border-radius: 2px;</span><br><span class="line">&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">style</span> <span class="attr">scoped</span> <span class="attr">lang</span>=<span class="string">"scss"</span>&gt;</span></span><br><span class="line"><span class="css"><span class="selector-id">#login</span> &#123;</span></span><br><span class="line">  display: flex;</span><br><span class="line">  flex-flow: row;</span><br><span class="line">  justify-content: flex-end;</span><br><span class="line">  align-items: center;</span><br><span class="line">  width: 100%;</span><br><span class="line">  height: 100%;</span><br><span class="line">  background-image: url("../assets/images/back.jpg");</span><br><span class="line">  background-size: 100% 100%;</span><br><span class="line"><span class="css">  <span class="selector-class">.loginFrom</span> &#123;</span></span><br><span class="line">    width: 300px;</span><br><span class="line">    margin-top: -10vw;</span><br><span class="line">    margin-right: 10vw;</span><br><span class="line"><span class="css">    <span class="selector-class">.login-item</span> &#123;</span></span><br><span class="line">      display: flex;</span><br><span class="line">      justify-content: center;</span><br><span class="line">      align-items: center;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="css">    <span class="selector-class">.login-title</span> &#123;</span></span><br><span class="line"><span class="css">      <span class="selector-tag">color</span>: <span class="selector-id">#ffffff</span>;</span></span><br><span class="line">      font-size: 16px;</span><br><span class="line">      margin-bottom: 10px;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="css">    <span class="selector-class">.login-bottom</span> &#123;</span></span><br><span class="line">      margin-top: 15px;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="css">    <span class="selector-class">.login-bottom</span><span class="selector-pseudo">:hover</span> &#123;</span></span><br><span class="line"><span class="css">      <span class="selector-tag">background</span>: <span class="selector-tag">rgba</span>(28, 136, 188, 0<span class="selector-class">.5</span>);</span></span><br><span class="line">    &#125;</span><br><span class="line"><span class="css">    <span class="selector-class">.login-bottom</span><span class="selector-pseudo">:active</span> &#123;</span></span><br><span class="line"><span class="css">      <span class="selector-tag">background</span>: <span class="selector-tag">rgba</span>(228, 199, 200, 0<span class="selector-class">.5</span>);</span></span><br><span class="line">    &#125;</span><br><span class="line">    /deep/.login-inputorbuttom &#123;</span><br><span class="line">      height: 40px;</span><br><span class="line">      width: 300px;</span><br><span class="line"><span class="css">      <span class="selector-tag">background</span>: <span class="selector-tag">rgba</span>(57, 108, 158, 0<span class="selector-class">.5</span>);</span></span><br><span class="line">      border-radius: 20px;</span><br><span class="line"><span class="css">      <span class="selector-tag">border</span>: <span class="selector-id">#396c9e</span> 1<span class="selector-tag">px</span> <span class="selector-tag">solid</span>;</span></span><br><span class="line">      font-size: 14px;</span><br><span class="line"><span class="css">      <span class="selector-tag">color</span>: <span class="selector-id">#ffffff</span>;</span></span><br><span class="line"><span class="css">      <span class="selector-class">.el-input--small</span>,</span></span><br><span class="line"><span class="css">      <span class="selector-class">.el-input__inner</span> &#123;</span></span><br><span class="line">        line-height: 43px;</span><br><span class="line">        border: none;</span><br><span class="line"><span class="css">        <span class="selector-tag">color</span>: <span class="selector-id">#ffffff</span>;</span></span><br><span class="line">        font-size: 14px;</span><br><span class="line">        height: 40px;</span><br><span class="line">        border-radius: 20px;</span><br><span class="line">        background: transparent;</span><br><span class="line">        text-align: center;</span><br><span class="line">      &#125;</span><br><span class="line"><span class="css">      <span class="selector-class">.el-input__icon</span> &#123;</span></span><br><span class="line">        line-height: 40px;</span><br><span class="line">        font-size: 16px;</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="css"><span class="comment">/*该样式最终是以弹窗插入*/</span></span></span><br><span class="line"><span class="css"><span class="selector-class">.sliding-pictures</span> &#123;</span></span><br><span class="line">  width: 100%;</span><br><span class="line"><span class="css">  <span class="selector-class">.vimg</span> &#123;</span></span><br><span class="line">    width: 100%;</span><br><span class="line">    height: 170px;</span><br><span class="line"><span class="css">    <span class="selector-id">#codeImg</span>,</span></span><br><span class="line"><span class="css">    <span class="selector-id">#sliderBlock</span> &#123;</span></span><br><span class="line">      padding: 7px 7px 0 7px;</span><br><span class="line">      width: inherit;</span><br><span class="line">      height: inherit;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="css">    <span class="selector-id">#codeImg</span> &#123;</span></span><br><span class="line">      //display: none;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="css">    <span class="selector-id">#sliderBlock</span> &#123;</span></span><br><span class="line">      position: absolute;</span><br><span class="line">      z-index: 4000;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"><span class="css">  <span class="selector-class">.slider</span> &#123;</span></span><br><span class="line">    width: 100%;</span><br><span class="line">    height: 65px;</span><br><span class="line"><span class="css">    <span class="selector-tag">border-bottom</span>: <span class="selector-id">#c7c9d0</span> 1<span class="selector-tag">px</span> <span class="selector-tag">solid</span>;</span></span><br><span class="line">    display: flex;</span><br><span class="line">    align-items: center;</span><br><span class="line">    justify-content: flex-start;</span><br><span class="line"><span class="css">    <span class="selector-class">.track</span> &#123;</span></span><br><span class="line">      margin-left: 7px;</span><br><span class="line">      width: 286px;</span><br><span class="line">      height: 38px;</span><br><span class="line"><span class="css">      <span class="selector-tag">background</span>: <span class="selector-tag">rgba</span>(28, 136, 188, 0<span class="selector-class">.5</span>);</span></span><br><span class="line">      border-radius: 25px;</span><br><span class="line">      font-size: 14px;</span><br><span class="line">      line-height: 38px;</span><br><span class="line">      padding-right: 15px;</span><br><span class="line">      padding-left: 70px;</span><br><span class="line">    &#125;</span><br><span class="line"><span class="css">    <span class="selector-class">.pintuTrue</span> &#123;</span></span><br><span class="line"><span class="css">      <span class="selector-tag">background</span>: <span class="selector-id">#67c23a</span>;</span></span><br><span class="line"><span class="css">      <span class="selector-tag">color</span>: <span class="selector-id">#ffffff</span>;</span></span><br><span class="line">    &#125;</span><br><span class="line"><span class="css">    <span class="selector-class">.button</span> &#123;</span></span><br><span class="line">      position: absolute;</span><br><span class="line">      width: 50px;</span><br><span class="line">      height: 50px;</span><br><span class="line">      line-height: 48px;</span><br><span class="line"><span class="css">      <span class="selector-tag">background</span>: <span class="selector-id">#ffffff</span>;</span></span><br><span class="line"><span class="css">      <span class="selector-tag">box-shadow</span>: <span class="selector-id">#b9bdc8</span> 0 0 3<span class="selector-tag">px</span>;</span></span><br><span class="line">      border-radius: 50%;</span><br><span class="line">      left: 7px;</span><br><span class="line">      text-align: center;</span><br><span class="line">      font-size: 28px;</span><br><span class="line"><span class="css">      <span class="selector-tag">color</span>: <span class="selector-id">#3e5d8b</span>;</span></span><br><span class="line"><span class="css">      &amp;<span class="selector-pseudo">:hover</span> &#123;</span></span><br><span class="line"><span class="css">        <span class="selector-tag">color</span>: <span class="selector-id">#2181bd</span>;</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"><span class="css">  <span class="selector-class">.operation</span> &#123;</span></span><br><span class="line">    width: 100%;</span><br><span class="line">    height: 40px;</span><br><span class="line">    &gt; span &#123;</span><br><span class="line"><span class="css">      <span class="selector-tag">color</span>: <span class="selector-id">#9fa3ac</span>;</span></span><br><span class="line">      display: inline-block;</span><br><span class="line">      width: 40px;</span><br><span class="line">      font-size: 25px;</span><br><span class="line">      line-height: 40px;</span><br><span class="line">      text-align: center;</span><br><span class="line"><span class="css">      &amp;<span class="selector-pseudo">:hover</span> &#123;</span></span><br><span class="line"><span class="css">        <span class="selector-tag">background</span>: <span class="selector-id">#e2e8f5</span>;</span></span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span><br></pre></td></tr></table></figure>

    </div>
    
    
    
    
    <div>
      
        <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>

      
    </div>
        <div class="reward-container">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button onclick="var qr = document.getElementById('qr'); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">
    打赏
  </button>
  <div id="qr" style="display: none;">
      
      <div style="display: inline-block;">
        <img src="/images/alipay.png" alt="Li Yudong 支付宝">
        <p>支付宝</p>
      </div>

  </div>
</div>

        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Li Yudong
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://example.com/2021/09/10/%E5%AD%A6%E6%A0%A1%E9%A1%B9%E7%9B%AE%E5%BA%94%E7%94%A8/%E6%BB%91%E5%8A%A8%E5%9B%BE%E7%89%87%E9%AA%8C%E8%AF%81%E7%A0%81/" title="滑动图片验证码">http://example.com/2021/09/10/学校项目应用/滑动图片验证码/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>

    
      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/%E5%AD%A6%E6%A0%A1%E9%A1%B9%E7%9B%AE%E5%BA%94%E7%94%A8/" rel="tag"># 学校项目应用</a>
          </div>
    
        

    
        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/09/06/%E7%AE%97%E6%B3%95/JS%E5%8A%9B%E6%89%A3%E5%88%B7%E9%A2%98%E8%AE%B0%EF%BC%88%E4%BA%8C%EF%BC%89/" rel="prev" title="JS力扣刷题记（二）">
      <i class="fa fa-chevron-left"></i> JS力扣刷题记（二）
    </a></div>
      <div class="post-nav-item">
    <a href="/2021/09/15/webgl/webgl%E6%96%B0%E6%89%8B%E6%95%99%E7%A8%8B/" rel="next" title="webgl编程指南初学">
      webgl编程指南初学 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、弹窗和弹窗组件"><span class="nav-number">1.1.</span> <span class="nav-text">一、弹窗和弹窗组件</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、编写基础结构"><span class="nav-number">1.2.</span> <span class="nav-text">二、编写基础结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#三、canvas绘制图片"><span class="nav-number">1.3.</span> <span class="nav-text">三、canvas绘制图片</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1、canvas绘制外部img图片"><span class="nav-number">1.3.1.</span> <span class="nav-text">1、canvas绘制外部img图片</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2、canvas绘制滑块部分"><span class="nav-number">1.3.2.</span> <span class="nav-text">2、canvas绘制滑块部分</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3、让元素跟随鼠标点击之后滑动"><span class="nav-number">1.3.3.</span> <span class="nav-text">3、让元素跟随鼠标点击之后滑动</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#四、完整的页面代码"><span class="nav-number">1.4.</span> <span class="nav-text">四、完整的页面代码</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Li Yudong"
      src="/images/author.jpg">
  <p class="site-author-name" itemprop="name">Li Yudong</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">95</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">18</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/tiarmor1" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;tiarmor1" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:1157019137@qq.com" title="E-Mail → mailto:1157019137@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>
  <div class="cc-license motion-element" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 2020 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Li Yudong</span>
</div>

        








      </div>
    </footer>
  </div>

  
  
  <script color='0,0,0' opacity='0.5' zIndex='-1' count='150' src="/lib1/canvas-nest/canvas-nest.min.js"></script>
  <script src="/lib1/anime.min.js"></script>
  <script src="/lib1/velocity/velocity.min.js"></script>
  <script src="/lib1/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  




  
<script src="/js/local-search.js"></script>













  

  

  
   <canvas class="fireworks" style="position: fixed;left: 0;top: 0;z-index: 1; pointer-events: none;" ></canvas> 
   <script type="text/javascript" src="//cdn.bootcss.com/animejs/2.2.0/anime.min.js"></script> 
   <script type="text/javascript" src="/js/fireworks.js"></script>
  
</body>
</html>

